home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc20 / gemfsc20.lzh / GNUGEM27 / VDIBEZ.C < prev    next >
C/C++ Source or Header  |  1993-03-24  |  9KB  |  333 lines

  1. /*
  2.  *    vdibez.c
  3.  *
  4.  *    Bindings for Bezier curves.
  5.  *
  6.  *      ++jrb   bammi@cadence.com
  7.  *      and Michal Jaegermann, ntomczak@vm.ucs.ulberta.ca
  8.  *
  9.  *    Some function have alias names in order to maintain a common
  10.  *    set of symbols with compilers which need symbols unique in the
  11.  *    first seven characters.  Besides this resolution is required
  12.  *    by "The Standard" :-)
  13.  *
  14.  *    ++jrb sync up with SpeedoGDOS docs
  15.  *
  16.  */
  17. #include "common.h"
  18. #ifndef _COMPILER_H
  19. # include <compiler.h>
  20. #endif
  21. #include <types.h>
  22.  
  23.  
  24. __EXTERN void vdi __PROTO((void));
  25.  
  26. #ifdef __DEF_ALL__
  27.  
  28. #define L_v_set_ap
  29. #define L_v_bez_co
  30. #define L_v_bez_on
  31. #define L_v_bez_of
  32. #define L_v_bez
  33. #define L_v_bez_fi
  34. #define L_v_bez_qu
  35.  
  36. #endif /* __DEF_ALL__ */
  37.  
  38.  
  39. #ifdef L_v_set_ap
  40.  
  41. /*
  42.  * Inform GDOS about  location and size of a buffer which  GDOS
  43.  * can use for creation of Bezier curves.
  44.  *      buf_p  is a pointer to an address of a buffer
  45.  *      size     its a buffer size in 16-bytes paragraphs
  46.  *
  47.  * If buf_p is NULL, then space for a buffer will be allocated
  48.  * by GDOS - using Malloc (who knows where to look for this space?)
  49.  *
  50.  * "Hand coding" required - function opcode does not fit into 0-255 range
  51.  */
  52. void
  53. v_set_app_buff (void *buf_p, int size)
  54. {
  55.     short *wptr = _intin;
  56.  
  57.     *wptr++ = (short) buf_p;           /* low word of an address */
  58.     *wptr++ = (short)((long)buf_p >> 16);  /* high word of an address */
  59.     *wptr =   (short) size;            /* size of buffer in paragraphs */
  60.                                            /* para == 16 bytes */
  61.      wptr = (short *)_contrl;
  62.     *wptr++ = -1;    /* 0  - opcode */
  63.     *wptr++ = 0;    /* 1 */
  64.      wptr++;        /* 2 */
  65.     *wptr++ = 3;    /* 3  - # of entries in _intin */
  66.      wptr++;        /* 4 */
  67.     *wptr++ = 6;    /* 5 - id */
  68.     *wptr    = 0;    /* 6 - dummy handle - really needed? */
  69.     vdi();        /* call vdi */
  70. }
  71. #endif /* L_v_set_ap */
  72.  
  73. #ifdef L_v_bez_co
  74.  
  75. /*
  76.  * If onoff is 1 then enable Bezier capabilities and
  77.  * find a number of segments per Bezier curve.
  78.  * Returns logarithm in a base of 2 from that number
  79.  *
  80.  * If onoff is 0 then disable Bezier capabilities and
  81.  * release memory allocated in v_set_app_buff call.
  82.  * Returns NOTHING!
  83.  */
  84.  
  85. int
  86. v_bez_con(int handle, int onoff)
  87. {
  88.     __vdi__(VDI_CONTRL_ENCODE(11, (unsigned short)(onoff), 0, 13), handle);
  89.     return(_intout[0]);
  90. }
  91. #endif /* L_v_bez_co */
  92.  
  93. #ifdef L_v_bez_on
  94.  
  95. /*
  96.  * v_bez_on (alias v_bezon)
  97.  * Enable Bezier capabilities.
  98.  * Returns maximum Bezier depth (a measure of smoothness). The return
  99.  * value can range from 0-7, and is the exponent of 2, giving the
  100.  * number of line segments that make up the curve.
  101.  * 0 == 2**0 == 1 == straight line and
  102.  * 7 == 2**7 == 128 line segments.
  103.  */
  104.  
  105. __asm__(".stabs \"_v_bezon\",5,0,0,_v_bez_on"); /* dept of clean tricks */
  106. int
  107. v_bez_on (int handle)
  108. {
  109.     _contrl[4] = 4;    /* dont know why, but atari docs say so! */
  110.     __vdi__(VDI_CONTRL_ENCODE(11, 1, 0, 13), handle);
  111.     _contrl[4] = 0;    /* clear it back */
  112.     return *_intout;
  113. }
  114. #endif /* L_v_bez_on */
  115.  
  116. #ifdef L_v_bez_of
  117.  
  118. /*
  119.  * v_bez_off (alias v_bezoff)
  120.  * Disable Bezier capabilities.
  121.  * Free space allocated by GDOS for Bezier curves.
  122.  * (see v_set_app_buff for memory alloc info)
  123.  */
  124. __asm__(".stabs \"_v_bezoff\",5,0,0,_v_bez_off"); /* dept of clean tricks */
  125. void
  126. v_bez_off (int handle)
  127. {
  128.     __vdi__(VDI_CONTRL_ENCODE(11, 0, 0, 13), handle);
  129. }
  130. #endif /* L_v_bez_of */
  131.  
  132. #ifdef L_v_bez
  133. /*
  134.  * Draw an unfilled Bezier curve
  135.  *      xyarr   - an array of 'count' pairs of control vertices
  136.  *      bezarr  - an array of flags specifying which control points
  137.  *        are jump points
  138.  *                bit 0  off - start of a polyline if not continuation
  139.  *                bit 0  on  - start of a Bezier segment
  140.  *                bit 1  on  - jump point (move to the next one without draw)
  141.  *
  142.  * Returns - a number of points in a Bezier curve
  143.  */
  144.  
  145. int
  146. v_bez(       int     handle,   /* Device handle we're drawing to */
  147.            int     count,    /* Number of points total... */
  148.        int    *xyarr,    /* The points in x1,y1,x2,y2 format */
  149.        char *bezarr,   /* Flag array, so that we can set start, jump pts */
  150.        int    *extent,   /* "bounding box coordinates */
  151.        int    *totpts,   /* number of resulting polygon points */
  152.        int    *totmoves) /* number of resulting moves  */
  153. {
  154.     short *end;
  155.     char *pbd = bezarr;
  156.     char *opbd = (char *)_intin;
  157. #ifndef __MSHORT__
  158.     short *optr;
  159.     int *iptr = xyarr;
  160. #endif
  161.  
  162.     int cntrl0 = 6;
  163.  
  164.     /* copy entries from bezarr to _intin packing and swaping bytes ???! */
  165.     /* this requirement for byte swapping  is not documented - if you     */
  166.     /* discount some old code example, but things seem to work this way  */
  167.     end  = (short *) (pbd + count);
  168.     while (pbd < (char *)end) {
  169.     *(opbd + 1) = *pbd++;
  170.     if (pbd >= (char *)end)
  171.         break;
  172.     *opbd = *pbd++;
  173.     opbd += 2;
  174.     }
  175. #ifdef __MSHORT__
  176.     _vdiparams[2] = (void *) xyarr;
  177.     _vdiparams[4] = (void *) extent;
  178. #else
  179.     /* copy xyarr into an array of shorts */
  180.  
  181.     optr = _ptsin;
  182.     end  = optr + count + count;
  183.     while (optr < end)
  184.         *optr++ = *xyarr++;
  185. #endif
  186.  
  187.     _contrl[2] = 2; /* dont know why, the atari docs say so without */
  188.     _contrl[4] = 6; /* any    explaination */
  189.  
  190.     __vdi__(VDI_CONTRL_ENCODE(cntrl0, count, ((count + 1) >> 1), 13), handle);
  191.  
  192.     _contrl[2] = 0;
  193.     _contrl[4] = 0;
  194.  
  195. #ifdef __MSHORT__
  196.     /* restore standard parameter block */
  197.     _vdiparams[2] = (void *) _ptsin;
  198.     _vdiparams[4] = (void *) _ptsout;
  199. #else
  200.     optr = _ptsout;
  201.     iptr = extent;
  202.     *iptr++ = *optr++;
  203.     *iptr++ = *optr++;
  204.     *iptr++ = *optr++;
  205.     *iptr    = *optr;
  206. #endif
  207.     *totmoves = _intout[1];
  208.     return(*totpts = _intout[0]);    /* number of points in Bezier */
  209. }
  210.  
  211. #endif /* L_v_bez */
  212.  
  213.  
  214. #ifdef L_v_bez_fi
  215.  
  216. /*
  217.  * v_bez_fill (alias _v_bezfill)
  218.  * Draw a filled Bezier curve
  219.  *      xyarr   - an array of 'count' pairs of control vertices
  220.  *      bezarr  - an array of flags specifying which control points
  221.  *        are jump points
  222.  *                bit 0  off - start of a polyline if not continuation
  223.  *                bit 0  on  - start of a Bezier segment
  224.  *                bit 1  on  - jump point (move to the next one without draw)
  225.  * Returns - a number of points in a filled Bezier curve
  226.  */
  227.  
  228. __asm__(".stabs \"_v_bezfill\",5,0,0,_v_bez_fill"); /* dept of clean tricks */
  229. int
  230. v_bez_fill(int handle,       /* Device handle we're drawing to */
  231.            int     count,    /* Number of points total... */
  232.        int    *xyarr,    /* The points in x1,y1,x2,y2 format */
  233.        char *bezarr,   /* Flag array, so that we can set start, jump pts */
  234.        int    *extent,   /* "bounding box coordinates */
  235.        int    *totpts,   /* number of resulting polygon points */
  236.        int    *totmoves) /* number of resulting moves  */
  237. {
  238.     short *end;
  239.     char *pbd = bezarr;
  240.     char *opbd = (char *)_intin;
  241. #ifndef __MSHORT__
  242.     short *optr;
  243.     int *iptr = xyarr;
  244. #endif
  245.  
  246.     int cntrl0 = 9;
  247.  
  248.     /* copy entries from bezarr to _intin packing and swaping bytes ???! */
  249.     /* this requirement for byte swapping  is not documented - if you     */
  250.     /* discount some old code example, but things seem to work this way  */
  251.     end  = (short *) (pbd + count);
  252.     while (pbd < (char *)end) {
  253.     *(opbd + 1) = *pbd++;
  254.     if (pbd >= (char *)end)
  255.         break;
  256.     *opbd = *pbd++;
  257.     opbd += 2;
  258.     }
  259. #ifdef __MSHORT__
  260.     _vdiparams[2] = (void *) xyarr;
  261.     _vdiparams[4] = (void *) extent;
  262. #else
  263.     /* copy xyarr into an array of shorts */
  264.  
  265.     optr = _ptsin;
  266.     end  = optr + count + count;
  267.     while (optr < end)
  268.         *optr++ = *xyarr++;
  269. #endif
  270.     _contrl[2] = 2; /* dont know why, the atari docs say so without */
  271.     _contrl[4] = 6; /* any    explaination */
  272.  
  273.     __vdi__(VDI_CONTRL_ENCODE(cntrl0, count, ((count + 1) >> 1), 13), handle);
  274.  
  275.     _contrl[2] = 0;
  276.     _contrl[4] = 0;
  277.  
  278. #ifdef __MSHORT__
  279.     /* restore standard parameter block */
  280.     _vdiparams[2] = (void *) _ptsin;
  281.     _vdiparams[4] = (void *) _ptsout;
  282. #else
  283.     optr = _ptsout;
  284.     iptr = extent;
  285.     *iptr++ = *optr++;
  286.     *iptr++ = *optr++;
  287.     *iptr++ = *optr++;
  288.     *iptr    = *optr;
  289. #endif
  290.     *totmoves = _intout[1];
  291.     return(*totpts = _intout[0]);    /* number of points in Bezier */
  292. }
  293. #endif /* L_v_bez_fi */
  294.  
  295. #ifdef L_v_bez_qu
  296.  
  297. /*
  298.  * v_bez_qual (alias v_bezqual)
  299.  * Set the quality / speed tradeoff when drawing Beizier curve
  300.  * quality is given in percents
  301.  *
  302.  * Returns an actual quality set.
  303.  *
  304.  * This function requires "hand coding" since subcode 99 does
  305.  * not fit into 5 bits required by VDI_CONTRL_ENCODE
  306.  */
  307. __asm__(".stabs \"_v_bezqual\",5,0,0,_v_bez_qual"); /* dept of clean tricks */
  308. int
  309. v_bez_qual (int handle, int percent, int *actual)
  310. {
  311.     short *wptr = _intin;
  312.  
  313.     *wptr++ = 32;
  314.     *wptr++ = 1;
  315.     *wptr  = percent;
  316.  
  317.      wptr = (short *)_contrl;
  318.     *wptr++ = 5;    /* 0  - opcode */
  319.     *wptr++ = 0;    /* 1 */
  320.      wptr++;        /* 2 */
  321.     *wptr++ = 3;    /* 3  - # of entries in _intin */
  322.     *wptr++ = 1;    /* 4 - atari doesnt say why! */
  323.     *wptr++ = 99;    /* 5 - id */
  324.     *wptr    = handle;    /* 6 - handle */
  325.     vdi();        /* call vdi */
  326.     _contrl[4] = 0;     /* clear it back */
  327.  
  328.     return (*actual = *_intout);
  329. }
  330. #endif /* L_v_bez_qu */
  331.  
  332. /* -eof- */
  333.